<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="裁判姓名" prop="no">
        <el-input v-model="queryParams.name" placeholder="请输入教练名称" clearable style="width: 150px;"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['merchant:index']">添加裁判</el-button>
      </el-form-item>
    </el-form>

    <el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange"
      :default-sort="defaultSort" @sort-change="handleSortChange">
      <el-table-column label="ID" prop="id" width="55" />
      <el-table-column label="裁判名称" align="center" prop="name" />
      <el-table-column label="头像" align="center" width="200">
        <template slot-scope="scope">
          <img class="list-qr" :src="imagePath + scope.row.avatar">
        </template>
      </el-table-column>
      <el-table-column label="等级" align="center" prop="level" />
      <!-- <el-table-column label="介绍" align="center" prop="introduce" /> -->
      <!-- <el-table-column label="机构简介" align="center" prop="intro" /> -->
      <!-- <el-table-column label="创建时间" align="center" prop="createTime"/> -->
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="星级" align="center" prop="star" />
      <el-table-column label="生日" align="center" prop="brithday" sortable="custom"
        :sort-orders="['descending', 'ascending']" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.brithday) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="国籍" align="center" prop="notionality" />
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="体重" align="center" prop="weight" />
      <el-table-column label="奖项" align="center" prop="awards" />
      <!-- <el-table-column label="球队" align="center" prop="teamId" /> -->
      <el-table-column label="创建时间" align="center" prop="createTime" sortable="custom"
        :sort-orders="['descending', 'ascending']" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['merchant:index']"
            @click="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" v-hasPermi="['merchant:index']"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" class="common-dialog" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-position="top">
        <el-row>
          <el-col :span="24">
            <el-form-item label="裁判名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入裁判名称" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="9">
            <el-form-item label="头像" prop="avatar">
              <el-upload :action="uploadAction" list-type="picture-card" :class="{ hide: hideUpload }"
                :file-list="uploadFiles" :auto-upload="true" :show-file-list="false" :headers="uploadHeader"
                :on-success="handleUploadSuccess">
                <img v-if="form.avatar" :src="imagePath + form.avatar" class="list-img" />
                <i v-if="!form.avatar" class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="等级" prop="style">
              <el-input v-model="form.level" placeholder="请输入等级" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="性别" prop="style">
              <el-input v-model="form.sex" placeholder="请输入性别" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="星级" prop="style">
              <el-input v-model="form.star" placeholder="请输入星级" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="价格" prop="style">
              <el-input v-model="form.price" placeholder="请输入价格" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="国籍" prop="style">
              <el-input v-model="form.notionality" placeholder="请输入国籍" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="身高" prop="style">
              <el-input v-model="form.height" placeholder="请输入身高" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="体重" prop="style">
              <el-input v-model="form.weight" placeholder="请输入体重" maxlength="30" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="奖项">
              <!-- <editor v-model="form.awards" :min-height="300" /> -->
              <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="form.awards">
          </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="简介">
              <editor v-model="form.intro" :min-height="300" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
            <el-col :span="24">
              <el-form-item label="球队" prop="organization">
                <el-select v-model="form.teamId" placeholder="请选择球队">
                  <el-option v-for="item in mtInstitutionList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
    
<script>
import { getToken } from '@/utils/auth';
import { getMtRefereeList, saveSetting, update, deleteMtReferee, getMtRefereeInfor } from "@/api/mtreferee";
export default {
  name: "MtcoachList",
  // components: { txMap },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 标题
      title: "",
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 搜索地点结果
      locationList: [],
      // 选中地址id
      locationValue: null,
      // 选中地址详情
      locationItem: {},
      // 默认排序
      defaultSort: { prop: 'createTime', order: 'descending' },
      // 商户类型
      typeOptions: [],
      //机构名称
      mtInstitutionList: [],
      // 表单参数
      form: {},
      // 上传地址0
      uploadAction: process.env.VUE_APP_SERVER_URL + 'backendApi/file/upload',
      // 隐藏上传
      hideUpload: false,
      // 上传文件列表
      uploadFiles: [],
      uploadHeader: { 'Access-Token': getToken() },
      // 图片根目录
      imagePath: "",
      // 查询参数
      queryParams: {
        page: 1,
        pageSize: 10,
        mtBasketballTeamId: null,
        name: '',
      },
      // 表单校验
      rules: {

      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 查询日志
    getList() {
      this.loading = true;
      getMtRefereeList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        console.log(response.data);
        this.list = response.data.content;
        this.total = response.data.totalElements;
        this.imagePath = response.data.imagePath;
        this.typeOptions = response.data.typeList;
        this.mtInstitutionList = response.data.mtInstitutionList;
        this.loading = false;
      });
    },
    // 搜索按钮操作
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },

    // 重置按钮操作
    resetQuery() {
      this.resetForm("queryForm");
      this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order)
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.multiple = !selection.length;
    },
    // 排序触发事件
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    // 新增按钮操作
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增裁判";
    },
    // 表单重置
    reset() {
      this.form = {
        id: "",
        name: "",
        avatar: "",
        level: "",
        sex: "",
        star: "",
        price: "",
        peculiarity: "",
        birthday: "",
        nationality: "",
        height: "",
        weight: "",
        awards: "",
        intro: ""
      };
      this.resetForm("form");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 提交按钮
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id) {
            update(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            saveSetting(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 修改按钮操作
    handleUpdate(row) {
      const app = this;
      app.reset();
      const id = row.id || this.ids;
      getMtRefereeInfor(id).then(response => {
        app.form = response.data.mtPlayer;
        app.open = true;
        app.title = "编辑裁判信息";
      });
    },
    // 删除按钮操作
    handleDelete(row) {
      const name = row.name || this.id;
      this.$modal.confirm('是否确认删除"' + name + '"的数据项？').then(function () {
        return deleteMtReferee(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    handleUploadSuccess(file) {
      this.form.logo = file.data.fileName;
    }
  }
};
</script>
<style scoped>
.common-dialog>>>.el-upload--picture-card {
  width: 60px;
  height: 50px;
  line-height: 60px;
}
</style>
    
    